package m3;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;


public class Producer {
    public static void main(String[] args) throws Exception {
        //连接服务器
        ConnectionFactory f=new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");

        Channel c=f.newConnection().createChannel();
        // 定义fanout类型交换机: logs
        c.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);

        // 向logs交换机发送消息
        while (true) {
            System.out.print("输入消息： ");
            String s = new Scanner(System.in).nextLine();
            /*
            参数：
                1.交换机的名字
                2.对于fanout交换机无效
             */
            c.basicPublish("logs", "", null, s.getBytes());
        }
    }
}
